package com.mhc.suzuki.encoder;

import com.alibaba.fastjson.JSON;
import com.mhc.suzuki.vo.MessageVO;
import lombok.extern.slf4j.Slf4j;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

/**
 * Created by HW
 * on 2017/9/13 10:49.
 * websocket message解码类
*/


@Slf4j
public class MessageEncoder implements Encoder.Text<MessageVO> {

    /**
    * messageVO 转为json字符串
    * @param messageVO
    * @return
    * @throws EncodeException
    */
    @Override
    public String encode(MessageVO messageVO) throws EncodeException {
        return JSON.toJSONString(messageVO);
    }

    /**
     *
     * @param endpointConfig
     */
    @Override
    public void init(EndpointConfig endpointConfig) {
        //config初始化
    }

    /**
     * config 销毁
     */
    @Override
    public void destroy() {
        //config 销毁
    }
}
